package global

import (
	"github.com/go-redis/redis"
	"github.com/jassue/go-storage/storage"
	"github.com/olivere/elastic/v7"
	"go-demo/config"
	clientv3 "go.etcd.io/etcd/client/v3"
	"go.uber.org/zap"
	"gorm.io/gorm"
)

type Application struct {
	Config  *config.Config
	Elastic *elastic.Client
	Mysql   *gorm.DB
	Redis   *redis.Client
	Log     *zap.Logger
	Etcd    *clientv3.Client
}

var App = new(Application)

func (app *Application) Disk(disk ...string) storage.Storage {
	// 若未传参，默认使用配置文件驱动
	diskName := app.Config.StorageConfig.Default
	if len(disk) > 0 {
		diskName = storage.DiskName(disk[0])
	}
	s, err := storage.Disk(diskName)
	if err != nil {
		panic(err)
	}
	return s
}
